* ===============================

* Title: Replication files for 'Analyzing International Organizations: How the Concepts We Use Affect the Answers We Get'
* Project: Re-analysis of Mansfield and Pevehouse IO 2006
* Author: Charles B. Roger; Sam S. Rowan
* Contact: croger@ibei.org; sam.rowan@concordia.ca
* Date: 1 April 2021

* ===============================

**** Set working directory ****

* Set working directory to 'Roger and Rowan RIO 2021' on your machine


* ===============================
****  Load in Mansfield and Pevehouse's data (JCR 2008 version), merge in new IO variables ****
* ===============================

use "data/input/manspeve_jcr.dta", replace

** Create MP region variables
gen reg_mp = 0 
replace reg_mp = 1 if NAmerica == 1 
replace reg_mp = 2 if SAmerica == 1 
replace reg_mp = 3 if MidEast == 1 
replace reg_mp = 4 if Asia == 1 
replace reg_mp = 5 if Oceania == 1 
replace reg_mp = 6 if Europe == 1 
label define values 0"Africa" 1"North America" 2"South America" 3"Middle East" 4"Asia" 5"Oceania" 6"Europe"
label value reg_mp values

** Mansfield and Pevehouse's sum and joined variables
gen mp_igos_sum = Npolitical_p + Nstandards_p + Neconomic_p 
gen mp_igos_joined = dEconomicp_1 + dStandardsp_1 + dPoliticalp_1 /* this is change in membership, not joining... has negative values */

* Check one of the MP JCR 2008 models: identical for main variables
// xtpcse dPoliticalp_1 MajorPower Neconomic_p Nstandards_p Npolitical_p Democratization Autocratization StableDemoc Dispute Hegemony year NAmerica SAmerica Asia Oceania Europe MidEast FormerCommunist Independence, corr (indep) pairwise

** Recode some country codes to facilitate merging

* Recode Germany
drop if ccode == 260 & year == 1990
drop if ccode == 265 & year == 1990

** Merge
merge 1:1 ccode year using "data/input/summaries_v3.dta"

drop if year > 2000
drop if year < 1965

** Set as time series
tsset ccode year

* Define a common sample
qui reg mp_igos_joined mp_igos_sum Democratization Autocratization StableDemoc Dispute Hegemony year FormerCommunist Independence i.reg_mp 
gen in_mp = e(sample) 

qui reg formals_sum_joined formals_sum_member Democratization Autocratization StableDemoc Dispute Hegemony year FormerCommunist Independence i.reg_mp 
gen in_formals = e(sample)

qui reg informals_sum_joined informals_sum_member Democratization Autocratization StableDemoc Dispute Hegemony year FormerCommunist Independence i.reg_mp 
gen in_informals = e(sample) 

tab in_mp in_formals 
tab in_mp in_informals
tab in_formals in_informals


// browse if in_mp==1 & in_formals == 0 
// browse if in_mp==1 & in_informals == 0 /* No 2000 in the MP original data */ 


* =============================== 
**** Re-analyze the data with new IO membership variables **** 
* =============================== 

** Set new working directory for tables
cd "data/output"

** MP model 1.1 with correct number of IOs joined
xtpcse mp_igos_joined mp_igos_sum Democratization Autocratization StableDemoc Dispute Hegemony year FormerCommunist Independence i.reg_mp if in_mp == 1, corr(indep) pairwise
outreg2 using mp_table2_main, se tex append dec(3) e(N) 10pct label

xtpcse formals_sum_joined formals_sum_member Democratization Autocratization StableDemoc Dispute Hegemony year FormerCommunist Independence i.reg_mp if in_mp == 1, corr(indep) pairwise
outreg2 using mp_table2_main, se tex append dec(3) e(N) 10pct label

xtpcse informals_sum_joined informals_sum_member Democratization Autocratization StableDemoc Dispute Hegemony year FormerCommunist Independence i.reg_mp if in_mp == 1, corr(indep) pairwise
outreg2 using mp_table2_main, se tex append dec(3) e(N) 10pct label

xtpcse total_sum_joined total_sum_member Democratization Autocratization StableDemoc Dispute Hegemony year FormerCommunist Independence i.reg_mp if in_mp == 1, corr(indep) pairwise
outreg2 using mp_table2_main, se tex append dec(3) e(N) 10pct label


* =============================== 
**** Standardized effects for the different IO variables ****
* =============================== 

** Create standardized versions of the key IO variables 

egen z_mp = std(mp_igos_joined)
egen z_formal = std(formals_sum_joined)
egen z_informal = std(informals_sum_joined)
egen z_total = std(formals_sum_joined)

** Re-run the models

qui xtpcse z_mp mp_igos_sum Democratization Autocratization StableDemoc Dispute Hegemony year FormerCommunist Independence i.reg_mp if in_mp == 1, corr(indep) pairwise
est store mp_mp

qui xtpcse z_formal formals_sum_member Democratization Autocratization StableDemoc Dispute Hegemony year FormerCommunist Independence i.reg_mp if in_mp == 1, corr(indep) pairwise
est store mp_formal

qui xtpcse z_informal informals_sum_member Democratization Autocratization StableDemoc Dispute Hegemony year FormerCommunist Independence i.reg_mp if in_mp == 1, corr(indep) pairwise
est store mp_informal

qui xtpcse z_total total_sum_member Democratization Autocratization StableDemoc Dispute Hegemony year FormerCommunist Independence i.reg_mp if in_mp == 1, corr(indep) pairwise
est store mp_total

** Save the outputs to disk

esttab mp_mp mp_formal mp_informal mp_total using mp_esttab.csv, replace se nostar plain keep(Democratization)
 
* =============================== * =============================== * =============================== * ===============================
* END. 
* =============================== * =============================== * =============================== * ===============================



 
